﻿Public Class UCLoaiNha

    Private Sub UCLoaiNha_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        GridView_Load()
    End Sub
    Sub GridView_Load()
        GControl.DataSource = LoaiNhaBUS.LoaiNha_Load()
    End Sub
    Function  TestInfo( ) As Boolean
        If txtTenln.Text = "" Then
            ThongBao.TestInfo()
            Return False
        End If
        Return True
    End Function 
    Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        If Not TestInfo() Then
            Return
        End If
        Dim ln As New LoaiNhaDTO()
        ln.Tenloainha = txtTenln.Text
        LoaiNhaBUS.LoaiNha_Insert(ln)
        GridView_Load()
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        If Not TestInfo() Then
            Return
        End If
        If Not ThongBao.Agree Then
            Return
        End If
        Dim ln As New LoaiNhaDTO()
        ln.MaLoaiNha = GView.GetFocusedRowCellDisplayText("MALOAINHA")
        ln.Tenloainha = txtTenln.Text
        LoaiNhaBUS.LoaiNha_Update(ln)
        GridView_Load()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        If Not ThongBao.Agree Then
            Return
        End If
        Dim ln As New LoaiNhaDTO()
        ln.MaLoaiNha = GView.GetFocusedRowCellDisplayText("MALOAINHA")
        LoaiNhaBUS.LoaiNha_Delete(ln)
        GridView_Load()
    End Sub

    Private Sub GView_RowCellClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs) Handles GView.RowCellClick
        txtMaln.Text = GView.GetFocusedRowCellDisplayText("MALOAINHA")
        txtTenln.Text = GView.GetFocusedRowCellDisplayText("TENLOAINHA")
    End Sub
End Class
